import {banner_list,food_type_list,food_recommend_list} from '../../network/interface'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerList: [],
    foodTypeList: [],
    foodRecommendList:[],
    pageNumber: 1,    //分页记录数
  },
  clickDetail:function(e){
    let id=e.currentTarget.dataset.id
    let name=e.currentTarget.dataset.name
    console.log("id:"+id)
    wx.navigateTo({
      url: '/pages/foodList/foodList?id='+id+'&name='+name
    })
  },
  tointroduce:function(e){
    let id=e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../foodIntroduce/foodIntroduce?id='+id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBannerList()
    this.getFoodTypeList()
    this.getRecommendList()
  },


  getRecommendList(){
    let params={}
    var that=this;
    params.type=1;
    food_recommend_list(params,res=>{
      if(res.data !==null){
        that.setData({
          foodRecommendList:res.data
        })
      }
    })
  },

  getFoodTypeList(){
    let params={}
    var that=this
    wx.showLoading({
      title: '加载中',
    })
    food_type_list(params,function success(res) {
      if(res['status']===200){
        that.setData({
          foodTypeList:res.data
        })
        wx.hideLoading({
          success: (res) => {},
        })
      }
    })
  },

  getBannerList(){
    let tokenInfo = wx.getStorageSync('token');
    console.log("token:"+tokenInfo)
    let params={}
    var that=this
    banner_list(params,function success(res) {
      if(res['status']===200){
        that.setData({
          bannerList:res.data
        })
      }
    })
  },
 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    wx.setStorage({
      key:"Id",
      data:0
    })
    this.getRecommendList()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
      this.getRecommendList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})